<?php
require_once("../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");


$type = "";
if (isset($_POST['Type']))$type=$_POST['Type'];
switch ($type)
{
	case 'sessions':
		echo '<p>Show sessions</p>';
		
		echo "<div id=\"admin-sessions\">\n";
		
		echo "<div class=\"admin-sessions-session\">\n";
		echo "<div class=\"admin-sessions-title admin-sessions-session-sessionid\">Session ID</div>\n";
		echo "<div class=\"admin-sessions-title admin-sessions-session-date\">Date</div>\n";
		echo "<div class=\"admin-sessions-title admin-sessions-session-user\">User</div>\n";
		echo "</div>\n";

		
		foreach($SESSIONS as $session)
		{
			echo "<div class=\"admin-sessions-session\">\n";
			echo "<div class=\"admin-sessions-session-sessionid\">".$session->getSessionID()."</div>\n";
			echo "<div class=\"admin-sessions-session-date\">".$session->getExpires()->format("D M d Y H:i")."</div>\n";
			echo "<div class=\"admin-sessions-session-user\">".$USERS[$session->getUserID()]['LongName']."</div>\n";
			echo "</div>\n";
		}

		echo "</div>\n";
		break;
		
		
	case 'users':
		echo "<div id=\"admin-users\">\n";
		
		echo "<div class=\"admin-users-user\">\n";
		echo "<div class=\"admin-users-title admin-users-user-username\">Username</div>\n";
		echo "<div class=\"admin-users-title admin-users-user-frequency\">Frequency</div>\n";
		echo "</div>\n";

		$sessions = new Sessions();
		$users = $sessions->getUsers();
		
		foreach($users as $userid => $count)
		{
			echo "<div class=\"admin-users-user\">\n";
			echo "<div class=\"admin-users-user-username\">".$USERS[$userid]['LongName']."</div>\n";
			echo "<div class=\"admin-users-user-count\">".$count."</div>\n";
			echo "</div>\n";
		}

		echo "</div>\n";
		break;
		
	case 'modifyUsers':
		echo "<div id=\"admin-modifyusers\">\n";
		
		echo "<div class=\"admin-modifyusers-user\">\n";
		echo "<div class=\"admin-modifyusers-user-title admin-modifyusers-user-longname\">Username</div>\n";
		echo "<div class=\"admin-modifyusers-user-title admin-modifyusers-user-shortname\">Abbr</div>\n";
		echo "<div class=\"admin-modifyusers-user-title admin-modifyusers-user-password\">Password</div>\n";
		echo "<div class=\"admin-modifyusers-user-title admin-modifyusers-user-email\">Email</div>\n";
		echo "<div class=\"admin-modifyusers-user-title admin-modifyusers-user-groupname\">Group</div>\n";
		echo "</div>\n";
		

		$users = $GLOBALS['USERS'];
//		print_r($users);
		foreach ($users as $user)
		{
			$userID = $user['SnapUserID'];
			echo "<div class=\"admin-modifyusers-user\" id=\"admin-modifyusers-user-".$userID."\" >\n";
			echo "<div class=\"admin-modifyusers-user-longname\">".$user['LongName']."</div>\n";
			echo "<div class=\"admin-modifyusers-user-shortname\">".$user['ShortName']."</div>\n";
			echo "<div class=\"admin-modifyusers-user-password\">".$user['Password']."</div>\n";
			echo "<div class=\"admin-modifyusers-user-email\">".$user['email']."</div>\n";
//			echo "<div class=\"admin-modifyusers-user-snapusergroupid\">".$user['SnapUserGroupID']."</div>\n";
			echo "<div class=\"admin-modifyusers-user-groupname\">".$user['GroupName']."</div>\n";
	
	
			echo "</div>\n"; //end of admin-modifyusers-user		
		}
		echo "</div>\n"; //end of admin-modifyusers			
		echo"<div id=\"admin-modifyusers-edit-dialog\" />";
		
		break;
		
	default:
		echo "<p>Admin tools</p>\n";
		break;
}
